#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "icar_log.h"
#include "icar_pkg.h"
#include "icar_end_msg.h"
#include "icar_flat_msg.h"
#include "icar_utils.h"
#include <stdint.h>

extern int idaemon;

int main(int argc, char **argv)
{
	icar_daemon(LOG_DEBUG, "Yes");
	char *num = "18689831418";
	int port = 60000;
	int i;

	char authcode[6000] = { 0 };
	memset(authcode, 'a', 5999);
	int n = strlen(authcode);
	struct icar_iovec *iovec;

	struct flatRes res;
	struct flatInfoMenu menu;
	struct regiser_res Res;
	res.sequence = 0x1234;
	res.endId = ICAR_END_HEARTBEAT;
	res.result = 0;
	iovec = flat_genricRes(0, num, &res);

	if (iovec)
		icar_print_iovec(iovec);

	free_iovec(iovec);

	Res.sequence = 0x3456;
	Res.result = 0;
	Res.len = 1024;
	Res.authcode = (char *)malloc(Res.len);
	memset(Res.authcode, 0, Res.len);

	strcpy(Res.authcode, "鄂A 8A5G5");

	iovec = end_unregister(0, num);
	if (iovec)
		icar_print_iovec(iovec);

	free_iovec(iovec);

	iovec = end_update_notice(0, num, 12, 0);

	if (iovec)
		icar_print_iovec(iovec);

	free_iovec(iovec);

	iovec = end_event_report(0, num, 12);
	if (iovec)
		icar_print_iovec(iovec);
	free_iovec(iovec);

	iovec = flat_temp_local_ctrl(0, num, 120, 3600 * 24);

	if (iovec)
		icar_print_iovec(iovec);

	free_iovec(iovec);

	iovec = flat_confirm_alarm(0, num, 0x1455, 0xabef7890);

	if (iovec)
		icar_print_iovec(iovec);

	free_iovec(iovec);


	bzero(&menu, sizeof(menu));
	menu.type = 0;
	menu.total = 5;
	for (i = 0; i < 5; i++) {
		menu.iov[i].type = 0x30 + i;
		menu.iov[i].iov_base = "杭州智驾科技";
		menu.iov[i].iov_len = strlen(menu.iov[i].iov_base) + 1;
	}

	iovec = flat_infoMenu_set(0, num, &menu);

	if (iovec) {
		icar_print_iovec(iovec);
	}

	free_iovec(iovec);

	iovec = end_infoMenu_cancel(0, num, 0, 1);

	if (iovec) {
		icar_print_iovec(iovec);
	}

	free_iovec(iovec);

	iovec = flat_infoServ(0, num, 4, menu.iov[3].iov_base, menu.iov[3].iov_len);

	if (iovec) {
		icar_print_iovec(iovec);
	}

	free_iovec(iovec);

	printf("sizeof(struct icar_iovec): %d\n", sizeof(struct icar_iovec));
	printf("sizeof(struct iovector): %d\n", sizeof(struct iovector));
	return 0;
}
